package binaryTree;

import java.util.Stack;

public class PosOrder {
	public static void posOrder(TreeNode root) {
		if(root!=null) {
			Stack<TreeNode> stack=new Stack<>();
			Stack<TreeNode> collect=new Stack<>();
			stack.push(root);
			while(!stack.isEmpty()) {
				root=stack.pop();
				collect.push(root);
				if(root.left!=null) {
					stack.push(root.left);
				}
				if(root.right!=null) {
					stack.push(root.right);
				}	
			}
			while(!collect.isEmpty()) {
				System.out.print(collect.pop().val+" ");
			}
		}
	}
	
}
